home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wdj0797.zip / SHMIDT.ZIP / VCALL32.ASM < prev    next >
Assembly Source File  |  1996-11-14  |  4KB  |  142 lines

  1.    title vcall32
  2.    page ,132
  3.  
  4. .386p
  5.  
  6. .xlist
  7.    include vmm.inc
  8.    include vwin32.inc
  9.    include winerror.inc
  10. ; winerror.inc sets this to none, this conflicts with /Cx
  11. option casemap:notpublic    
  12.    include vw32svc.inc
  13. .list
  14.  
  15. VCall32_Major   equ     1
  16. VCall32_Minor   equ     0
  17.  
  18. VWIN32_DIOC equ 0002A001Fh
  19.  
  20. VxD_DATA_SEG
  21. ; Win32 DeviceIOControl dispatch table
  22. align 4
  23. ioctltbl    label   dword
  24.    dd  offset32 ioctl_openclose
  25.    dd  offset32 ioctl_openclose
  26.    dd  offset32 ioctl_GetVersion
  27.    dd  offset32 ioctl_GetVxDCall
  28. ioctlcnt equ ($-ioctltbl)/4
  29.  
  30. vcall    dd 0   ; address of VxDCall PM Callback
  31. diocprev dd 0   ; pointer to the previos DIOC handler
  32. paramcnt dd 0   ; Win32 DIOC handler's DWORD parameter count
  33. VxD_DATA_ENDS
  34.  
  35. Declare_Virtual_Device VCALL32, \
  36.                        VCall32_Major, \
  37.                        VCall32_Minor, \
  38.                        VCall32_Control
  39.  
  40. VxD_LOCKED_CODE_SEG
  41.  
  42. VCall32_Control proc
  43. Control_Dispatch SYS_DYNAMIC_DEVICE_INIT, VCall32_DynamicInit
  44. Control_Dispatch SYS_DYNAMIC_DEVICE_EXIT, VCall32_DynamicExit
  45. Control_Dispatch W32_DEVICEIOCONTROL, VCall32_W32dioc
  46.    clc
  47.    ret
  48. VCall32_Control endp
  49.  
  50. VCall32_DynamicInit proc
  51.    cCall   _Get_Win32_Param_Count,<VWIN32_DIOC>
  52.    mov     [paramcnt], eax
  53.    ; hook DeviceIOCOntrol win32 service
  54.    cCall   _Hook_Win32_Service,<VWIN32_DIOC,\
  55.                                <offset32 Dioc_Handler>>
  56.    mov     [diocprev], eax
  57.  
  58.    clc
  59.    ret
  60. VCall32_DynamicInit endp
  61.  
  62. VCall32_DynamicExit proc
  63.    ; unhook w32 service
  64.    cCall   _Unhook_Win32_Service,<VWIN32_DIOC,\
  65.                                  <offset32 Dioc_Handler>>
  66.    clc
  67.    ret
  68. VCall32_DynamicExit endp
  69.  
  70. VCall32_W32dioc proc uses esi edi ebx ebp
  71.    ; get ioctl index
  72.    ; increment it for CLOSEHANDLE to start the table
  73.    mov   eax, [esi].dwIoControlCode
  74.    inc   eax
  75.    .IF eax >= ioctlcnt
  76.       ; not supported service number
  77.       mov   eax, ERROR_NOT_SUPPORTED
  78.       stc
  79.    .ELSE
  80.       ; call through the ioctl branch table
  81.       call    ioctltbl[eax*4]
  82.  
  83.       xor   eax, eax
  84.       clc
  85.    .ENDIF
  86.    ret
  87. VCall32_W32dioc  endp
  88.  
  89. ; deviceIOcontrol services
  90. ioctl_openclose proc
  91.    ret    
  92. ioctl_openclose endp
  93.  
  94. ioctl_GetVersion proc
  95.    .IF [esi].cbOutBuffer >= 4
  96.       mov     esi, [esi].lpvOutBuffer
  97.       mov     dword ptr [esi],(VCall32_Major shl 8)+VCall32_Minor
  98.    .ENDIF
  99.    ret
  100. ioctl_GetVersion endp
  101.  
  102. ioctl_GetVxDCall proc
  103.    .IF [esi].cbOutBuffer >= 4
  104.       mov     esi, [esi].lpvOutBuffer
  105.       mov     eax, [vcall]
  106.       mov     [esi], eax
  107.    .ENDIF
  108.    ret
  109. ioctl_GetVxDCall endp
  110.  
  111. Dioc_Handler proc
  112.    mov     eax, [esp+4]    ; pointer to CRS
  113.    ; the Win32 service dispatcher has already adjusted
  114.    ; the client stack - walk it backwards
  115.    mov     eax, [eax].Client_ESP
  116.  
  117.    ; get the numnber if DeviceIOControl Win32 service parameters
  118.    mov     edx, [paramcnt]
  119.    ; add 1 DWORD for near return from VxDCall, 
  120.    ; and 2 more for far return from [3b:xxxx] call
  121.    add     edx, 3
  122.    ; canver to a number of bytes
  123.    shl     edx, 2
  124.  
  125.    ; land at the place where the call to PM callback was made
  126.    sub     eax, edx
  127.    ; get the VxDCall IP where PM callback would have returned
  128.    ; if was not simulated
  129.    mov     eax, [eax]
  130.    ; get the pointer where PM callback is stored
  131.    mov     eax, [eax-4]
  132.    ; save it to return later to VCALL.DLL
  133.    mov     [vcall], eax
  134.  
  135.    ; jump to the real Win32 service handler
  136.    mov     edx, [diocprev]
  137.    jmp     [edx]
  138. Dioc_Handler endp
  139.  
  140. VxD_LOCKED_CODE_ENDS
  141.    end
  142.